package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.OrderReturnReason;
import com.itheima.mapper.OrderReturnReasonMapper;
import com.itheima.service.IOrderReturnReasonService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 退货原因表 服务实现类
 * </p>
 *
 * @author fukeke
 * @since 2022-11-11
 */
@DubboService
public class OrderReturnReasonServiceImpl extends ServiceImpl<OrderReturnReasonMapper, OrderReturnReason> implements IOrderReturnReasonService {
    @Autowired
    private OrderReturnReasonMapper orderReturnReasonMapper;


    //分页查询退货原因
    public Page selectByPage(Integer pageNum, Integer pageSize) {
        Page page = new Page(pageNum, pageSize);
        QueryWrapper<OrderReturnReason> qw = new QueryWrapper<>();
        qw.orderByDesc("sort", "create_time");
        return orderReturnReasonMapper.selectPage(page, qw);
    }

    //根据id，获取单个退货原因详情信息
    public OrderReturnReason findById(Long id) {
        return orderReturnReasonMapper.selectById(id);
    }

    //修改退货原因
    public Integer updateReturnReason(OrderReturnReason reason) {
        return orderReturnReasonMapper.updateById(reason);
    }

    //批量删除退货原因
    public Integer deleteByIds(List<Long> ids) {
        return orderReturnReasonMapper.deleteBatchIds(ids);
    }

    @Override
    public Integer saveReson(OrderReturnReason reason) {
        return orderReturnReasonMapper.insert(reason);
    }

}
